<template>
  <div class="performanceInterview-box content-box">
    <nav-title :title="from == 'approveList'? '绩效面谈审批':'绩效面谈'" :routerLink="routerLink"/>
    <div class="regulations-box">
      <div class="title">基本信息</div>
      <div class="information">
        <div class="info-cell clearfix">
          <label class="label">员工ID</label>
          <span class="value" style="font-size: 14px;" >{{allInfo.emplid}}</span>
        </div>
        <div class="info-cell clearfix">
          <label class="label">姓名</label>
          <span class="value" style="font-size: 14px;" >{{allInfo.name}}</span>
        </div>
        <div class="info-cell clearfix">
          <label class="label">部门</label>
          <span class="value" style="font-size: 14px;" >{{allInfo.dept}}</span>
        </div>
        <div class="info-cell clearfix">
          <label class="label">岗位</label>
          <span class="value" style="font-size: 14px;" >{{allInfo.jobDescr}}</span>
        </div>
      </div>
    </div>
    <div class="performanceInterview-list regulations-box">
      <div class="title">绩效结果</div>
      <div class="performanceInterview-list-row">
        <div class="label">考核模板</div>
        <div class="value">{{allInfo.tempName}}</div>
      </div>
      <div class="performanceInterview-list-row">
        <div class="label">排名组</div>
        <div class="value">{{allInfo.groupName}}</div>
      </div>
      <div class="performanceInterview-list-col-box">
        <div>
          <div class="label">绩效得分</div>
          <div class="value">{{allInfo.score}}</div>
        </div>
        <div>
          <div class="label">排名</div>
          <div class="value">{{allInfo.ranking}}</div>
        </div>
      </div>
      <div class="performanceInterview-list-col-box">
        <div>
          <div class="label">绩效等级</div>
          <div class="value">{{allInfo.level}}</div>
        </div>
        <div>
          <div class="label">绩效系数</div>
          <div class="value">{{allInfo.rate}}</div>
        </div>
      </div>
    </div>
    <div class="regulations-box">
        <div class="title">面谈内容</div>
        <div class="info-label">当前阶段重点工作达成回顾：</div>
        <group>
          <x-textarea :max="200" :readonly="!edit" placeholder="请在这里输入..." v-model="allInfo.cEpReach"/>
        </group>
        <div class="info-label">当前阶段存在不足：</div>
        <group>
          <x-textarea :max="200" :readonly="!edit" placeholder="请在这里输入..." v-model="allInfo.cEpDeficiencies"/>
        </group>
        <div class="info-label">下阶段绩效改进计划：</div>
        <group>
          <x-textarea :max="200" :readonly="!edit" placeholder="请在这里输入..." v-model="allInfo.cEpImprPlan"/>
        </group>
        <div class="info-label">360能力短板提升计划：</div>
        <group>
          <x-textarea :max="200" :readonly="!edit" placeholder="请在这里输入..." v-model="allInfo.cEpCpbPlan"/>
        </group>
        <div class="info-label">所需帮助：</div>
        <group>
          <x-textarea :max="200" :readonly="!edit" placeholder="请在这里输入..." v-model="allInfo.cEpReqHelp"/>
        </group>
      </div>

      <!-- 流程图 -->
    <div class="regulations-box" v-if="from == 'approveList'">
      <div class="title">面谈审批人</div>
      <v-flow-charts :type="'performanceInterview'" :docid="docid" :version="version" :epPhase="epPhase"></v-flow-charts>
    </div>
    <!-- 审批意见 -->
    <div class="regulations-box" v-if="from == 'approveList'">
      <div class="info-label">面谈反馈意见</div>
      <div class="info-label-text">
        <textarea :readonly="!edit" placeholder="请在这里输入..." rows="5" v-model="allInfo.cComments"></textarea>
        <!-- <textarea v-else="" readonly rows="5" v-model="allInfo.cComments"></textarea> -->
      </div>
    </div>

    <div v-if="(from == 'performanceResult' || from == 'todoList') && edit" class="PerformanceInterview-list-button">
      <button @click="saveOrSubmit('save')">保 存</button>
      <button @click="saveOrSubmit('commit')">提 交</button>
    </div>
    <div v-if="from == 'approveList' && approved == 0" class="PerformanceInterview-list-button">
      <button @click="saveOrAgree('SAVE')">保 存</button>
      <button @click="saveOrAgree('APPROVE')">同 意</button>
    </div>
  </div>
</template>

<script>
import { XTextarea, Group } from "vux";
import vFlowCharts from "../formalStaff/common/flowChart";
import {
  perresultGetIntrvwInfo,
  perresultSaveIntrvwTbl,
  perresultIntrvwPlanMap,
  perresultApproveIntrvw
} from "../../api/api";
import qs from "qs";

export default {
  name: "PerformanceInterview",
  components: {
    XTextarea,
    Group,
    vFlowCharts
  },
  created() {
    this.docid = this.$route.query.docid;
    this.epPhase = this.$route.query.epPhase;
    this.year = this.$route.query.year;
    this.version = this.$route.query.version;
    this.from = this.$route.query.from;
    this.cTransactionNbr = this.$route.query.cTransactionNbr;
    this.emplid = this.$route.query.emplid;
    this.approved = this.$route.query.approved;
  },
  mounted() {
    this.getData();
  },
  data() {
    return {
      routerLink: "",
      allInfo: {},
      edit: false
    };
  },
  methods: {
    getData() {
      this.$vux.loading.show();
      let params = {};
      if (this.from == "performanceResult") {
        params = {
          docid: this.docid,
          year: this.year,
          version: this.version
        };
      } else if (this.from == "approveList") {
        params = {
          cTransactionNbr: this.cTransactionNbr,
          emplid: this.emplid
        };
      } else if (this.from == "todoList") {
        params = {
          cTransactionNbr: this.cTransactionNbr
        };
      }
      perresultGetIntrvwInfo(params)
        .then(res => {
          this.$vux.loading.hide();
          if (res && res.retCode === "000000") {
            this.allInfo = res.retData;
            if (
              res.retData.status == "N" ||
              res.retData.status == "P" ||
              this.approved == 0
            ) {
              this.edit = true;
            }
          } else {
            this.$vux.alert.show({
              title: "提示",
              content: res.retMsg
            });
          }
        })
        .catch(res => {
          this.$vux.loading.hide();
          this.$vux.alert.show({
            title: "警告",
            content: "网络异常，请稍后重试"
          });
        });
    },
    saveOrSubmit(type) {
      let params = {
        cEpReach: this.allInfo.cEpReach,
        cEpDeficiencies: this.allInfo.cEpDeficiencies,
        cEpImprPlan: this.allInfo.cEpImprPlan,
        cEpCpbPlan: this.allInfo.cEpCpbPlan,
        cEpReqHelp: this.allInfo.cEpReqHelp,
        docid: this.docid || this.allInfo.docid,
        version: this.version || this.allInfo.version,
        year: this.year || "",
        type
      };
      if (type == "commit") {
        this.$vux.confirm.show({
          title: "提示",
          content: `是否确认提交？`,
          onConfirm: () => {
            this.$vux.loading.show();
            perresultSaveIntrvwTbl(qs.stringify(params))
              .then(res => {
                this.$vux.loading.hide();
                if (res && res.retCode === "000000") {
                  this.$router.go(-1);
                } else {
                  this.$vux.alert.show({
                    title: "提示",
                    content: res.retMsg
                  });
                }
              })
              .catch(res => {
                this.$vux.loading.hide();
                this.$vux.alert.show({
                  title: "警告",
                  content: "网络异常，请稍后重试"
                });
              });
          }
        });
      } else {
        this.$vux.loading.show();
        perresultSaveIntrvwTbl(qs.stringify(params))
          .then(res => {
            this.$vux.loading.hide();
            if (res && res.retCode === "000000") {
              this.$vux.alert.show({
                title: "成功",
                content: "保存成功！",
                onHide: () => {
                  this.$router.go(-1);
                }
              });
            } else {
              this.$vux.alert.show({
                title: "提示",
                content: res.retMsg
              });
            }
          })
          .catch(res => {
            this.$vux.loading.hide();
            this.$vux.alert.show({
              title: "警告",
              content: "网络异常，请稍后重试"
            });
          });
      }
    },
    saveOrAgree(type) {
      let params = {
        cEpReach: this.allInfo.cEpReach,
        cEpDeficiencies: this.allInfo.cEpDeficiencies,
        cEpImprPlan: this.allInfo.cEpImprPlan,
        cEpCpbPlan: this.allInfo.cEpCpbPlan,
        cEpReqHelp: this.allInfo.cEpReqHelp,
        docid: this.docid || this.allInfo.docid,
        version: this.version || this.allInfo.version,
        year: this.year || "",
        type,
        cComments: this.allInfo.cComments
      };
      if (type == "APPROVE") {
        this.$vux.confirm.show({
          title: "提示",
          content: `是否确认提交？`,
          onConfirm: () => {
            this.$vux.loading.show();
            perresultApproveIntrvw(qs.stringify(params))
              .then(res => {
                this.$vux.loading.hide();
                if (res && res.retCode === "000000") {
                  this.$router.go(-1);
                } else {
                  this.$vux.alert.show({
                    title: "提示",
                    content: res.retMsg
                  });
                }
              })
              .catch(res => {
                this.$vux.loading.hide();
                this.$vux.alert.show({
                  title: "警告",
                  content: "网络异常，请稍后重试"
                });
              });
          }
        });
      } else {
        this.$vux.loading.show();
        perresultApproveIntrvw(qs.stringify(params))
          .then(res => {
            this.$vux.loading.hide();
            if (res && res.retCode === "000000") {
              this.$vux.alert.show({
                title: "成功",
                content: "保存成功！",
                onHide: () => {
                  this.$router.go(-1);
                }
              });
            } else {
              this.$vux.alert.show({
                title: "提示",
                content: res.retMsg
              });
            }
          })
          .catch(res => {
            this.$vux.loading.hide();
            this.$vux.alert.show({
              title: "警告",
              content: "网络异常，请稍后重试"
            });
          });
      }
    }
  }
};
</script>

<style type="text/scss" lang="scss">
@import "../../styles/staff.scss";
.performanceInterview-box {
  .regulations-box {
    .weui-cell__bd {
      border: 1px solid #ccc;
    }
  }
  .performanceInterview-list {
    // border-bottom: 1px solid #ccc;
    text-align: left;
    font-size: 16px;
    div {
      line-height: 2;
    }
    .performanceInterview-list-row {
      width: 100%;
      display: flex;
      line-height: 32px;
      box-sizing: border-box;
      > div:first-child {
        // flex: 1;
        width: 90px;
        flex: none;
        text-align: right;
      }
      > div:last-child {
        // flex: 2;
        width: 100%;
        color: #999;
        padding-left: 20px;
        box-sizing: border-box;
      }
    }
    .performanceInterview-list-col-box {
      width: 100%;
      display: flex;
      > div {
        flex: 1;
        > div:first-child {
          // flex: 2;
          width: 90px;
          display: inline-block;
          text-align: right;
        }
        > div:last-child {
          // flex: 1;
          display: inline-block;
          padding-left: 20px;
          color: #999;
        }
      }
    }
  }
  .PerformanceInterview-list-button {
    width: 100%;
    padding: 10px;
    text-align: center;
    margin-bottom: 20px;
    > button {
      padding: 8px 20px;
      font-size: 16px;
      border-radius: 5px;
      color: #fff;
      font-weight: bold;
      margin: 0 20px;
    }
    > button:first-child {
      background-color: rgba(28, 170, 254, 1);
    }
    > button:last-child {
      background-color: rgba(255, 152, 0, 1);
    }
  }
}
</style>
